<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page
	import="com.onlineMIS.common.Common_util,java.util.Date,java.text.SimpleDateFormat"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>千禧宝贝连锁店管理信息系统</title>
<%@ include file="../../common/Style.jsp"%>
<link href="<%=request.getContextPath()%>/conf_files/css/pagination.css"
	rel="stylesheet" type="text/css" />
<SCRIPT src="<%=request.getContextPath()%>/conf_files/js/pagenav1.1.js"
	type=text/javascript></SCRIPT>
<script>

var dataGrid ;
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	var params= $.serializeObject($('#SalesOrderSearchForm'));
	
	dataGrid =  $('#dataGrid').datagrid({
		url : 'chainSalesJSONAction!searchSalesOrder',
		queryParams: params,
		fit : true,
		fitColumns : true,
		pagination : true,
		pageSize : 15,
		pageList : [ 15, 30],
		border : false,
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:true,
		showFooter:true,
		rownumbers:true,
		nowrap : false,
		rowStyler: function(index,row){
			var style = "";
			if (row.status == 3)
				style += 'color:red;';				
			else if (row.status == 1)
				style += 'color:blue;';
			return style;
		},		
		columns : [ [
				    {field:'id', width:6,title:'单据号'},
					{field:'chainName', width:14,title:'连锁店'},
					{field:'orderDate', width:8,title:'单据日期'},
					{field:'orderCreateDate', width:10,title:'过账日期'},
					{field:'statusS', width:5,title:'状态'},
					{field:'isVip', width:7,title:'VIP'},
					{field:'chainSalerName', width:5,title:'经手人'},
					{field:'totalQuantity', width:5,title:'销售数量'},
					{field:'netAmount', width:5,title:'销售金额',
						formatter : function(value, row, index) {		      	      
							return parsePFormt(row.netAmount);
						}},
					{field:'discount', width:5,title:'销售折扣',
							formatter : function(value, row, index) {		      	      
								return parsePFormt(row.discount);
							}},					
					{field:'totalQuantityR', width:5,title:'退货数量'},
					{field:'netAmountR', width:5,title:'退货金额',
						formatter : function(value, row, index) {		      	      
							return parsePFormt(row.netAmountR);
						}},
					{field:'totalQuantityF', width:5,title:'赠品数量'},
					{field:'memo', width:14,title:'单据摘要'},
					{
						field:'details', 
						width:5,
						title:'详情',
						formatter : function(value, row, index) {
							var str = '';
							var urlLink = "chainSalesJSPAction!getSalesOrderById?formBean.chainSalesOrder.id=" + row.id;			      	      
				 	    	var nodeTitle = "销售单";

							if (row.id != 0){							  
								   str += $.formatString('<a href="javascript:addTab3(\'{0}\',\'{1}{2}\');"><img border="0" src="{3}" title="详情"/></a>',urlLink,nodeTitle,  row.id,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/text_1.png');
								
							}
							return str;
						}
					},{field:'isHide',
					   width:5,
					   title:'过滤',
					   formatter : function(value, row, index) {
							var str = '';

							if (row.isHide != 0){							  
								   str += $.formatString('<a href="#" onclick="hideOrder(\'{0}\');"><img border="0" src="{1}" title="过滤"/></a>',  row.id,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/lock.png');
							}
							return str;
						}
					   },
			     ]],
		toolbar : '#toolbar'
	
	});
});


//pageNav.fn = function(page,totalPage){
//	$.messager.progress({
//		title : '提示',
//		text : '数据处理中，请稍后....'
//	});
//	$("#currentPage").val(page);
//    var params=$("#SalesOrderSearchForm").serialize();  
//    $.post("chainSalesJSONAction!searchSalesOrder",params, searchOrdersBackProcess,"json");	
//};

function searchOrders(){
	var params = $.serializeObject($('#SalesOrderSearchForm')); 
	$('#dataGrid').datagrid('load',params); 
}

/**
 * 查询单据详情
 */
function selectOrderDetails(orderId){
	$.messager.progress({
		title : '提示',
		text : '数据处理中，请稍后....'
	});
	window.location.href = "chainSalesJSPAction!getSalesOrderById?formBean.chainSalesOrder.id=" + orderId;

}


/**
 * 隐藏单据
 */
function hideOrder(orderId){
	var msg = '你确认将'+orderId+'单据业绩隐藏?'
	$.messager.confirm('确认', msg, function(r){
		if (r){
			var params= "formBean.chainSalesOrder.id=" + orderId;
			
			$.post("actionChain/chainSalesJSONAction!hiddenSalesOrder",params, hiddenOrderBackProcess,"json");
		}
	});

}

function hiddenOrderBackProcess(data){
	if(data.success){
		searchOrders();
	}else{
		  $.messager.alert('提示',data.message,'warning');
	}
}


/**
 * after change the chain store, we need change the user list and customer groups as well
 */
function changeChainStore(chainId){
	var params = "formBean.chainSalesOrder.chainStore.chain_id=" + chainId;
	$.post("chainSalesJSONAction!changeChainStore",params, backProcessChangeChainStore,"json");
}
function backProcessChangeChainStore(data){
	var chainUsers =  data.chainUsers;
	$("#chainSaler").empty();
	if (chainUsers.length != 0 ){
		$("#chainSaler").prepend("<option value='-1'>--所有人员--</option>");
		for (var i = 0; i < chainUsers.length; i++)
			   $("#chainSaler").append("<option value='"+chainUsers[i].user_id+"'>"+chainUsers[i].name+"</option>"); 
	}
}

function downloadSalesOrder(){
	document.SalesOrderSearchForm.action="chainSalesJSPAction!downloadSalesOrder";
	document.SalesOrderSearchForm.submit();
}
</script>
</head>
<body>

<div class="easyui-layout" data-options="fit : true,border : false">
	<div data-options="region:'north',border:false" style="height: 135px;">
	<s:form id="SalesOrderSearchForm" name="SalesOrderSearchForm"
		action="/actionChain/salesAction!searchOrders" theme="simple"
		method="POST">
		<input type="hidden" id="indicator" name="formBean.indicator"
			value="-1" />
		<input type="hidden" id="accessLevel" name="formBean.accessLevel"
			value="4" />
		<%@ include file="../../common/pageForm.jsp"%>
		<table width="98%" align="center" class="OuterTable">
			<tr>
				<td>
					<table width="100%" border="0">
						<tr>
							<td height="50" colspan="7">
								<table width="100%" border="0">
									<tr class="InnerTableContent">
										<td height="10" colspan="7"><s:actionerror
												cssStyle="color:red" />
											<s:actionmessage cssStyle="color:blue" /></td>
									</tr>
									<tr class="InnerTableContent">
										<td width="45" height="30">&nbsp;</td>
										<td width="76"><strong>单据日期</strong></td>
										<td width="284"><s:textfield id="startDate"
												name="formBean.search_Start_Time" cssClass="easyui-datebox"
												data-options="width:100,editable:false" /> &nbsp; 至&nbsp; <s:textfield
												id="endDate" name="formBean.search_End_Time"
												cssClass="easyui-datebox"
												data-options="width:100,editable:false" /></td>
										<td width="71"><strong>单据状态</strong></td>
										<td width="140"><s:select id="status"
												name="formBean.chainSalesOrder.status"
												list="uiBean.chainOrderStatus" listKey="key"
												listValue="value" headerKey="-1" headerValue="--所有状态--" /></td>
										<td width="77"><strong>付款方式</strong></td>
										<td><s:select id="chainOrderPay"
												name="formBean.chainOrderPay" list="uiBean.chainOrderPay"
												listKey="key" listValue="value" headerKey="-1"
												headerValue="--所有付款方式--" /></td>
									</tr>
									<tr class="InnerTableContent">
										<td height="30">&nbsp;</td>
										<td><strong>连锁店</strong></td>
										<td><%@ include file="../include/SearchChainStore.jsp"%></td>
										<td><strong>经手人</strong></td>
										<td><s:select id="chainSaler"
												name="formBean.chainSalesOrder.saler.user_id"
												list="uiBean.chainSalers" listKey="user_id" listValue="name"
												headerKey="-1" headerValue="--所有人员--" /></td>
										<td></td>
										<td></td>
									</tr>
									<tr class="InnerTableContent">
										<td height="30">&nbsp;</td>
										<td><strong>包含货品</strong></td>
										<td><%@ include file="../include/SearchProduct.jsp"%></td>
										<td><strong>单据号</strong></td>
										<td><s:textfield id="orderId"
												name="formBean.chainSalesOrder.id"
												cssClass="easyui-numberbox" value="0"
												data-options="min:0,precision:0" size="15" /></td>
										<td></td>
										<td></td>
									</tr>

								</table>
							</td>
						</tr>
						<!-- 
						<tr class="InnerTableContent">
							<td height="4" colspan="7"><hr width="100%" color="#FFCC00" /></td>
						</tr>
						<tr>
							<td colspan="7">
								
								<div id="salesOrdersDIV" style="display: none">
									<table width="100%" align="left" id="org_table">
										<tr class="PBAInnerTableTitale" align="center">
											<th width="20" height="35"></th>
											<th width="45">单据号</th>
											<th width="110">连锁店</th>
											<th width="75">单据日期</th>
											<th width="85">过账日期</th>
											<th width="40">状态</th>
											<th width="50">VIP</th>
											<th width="70">经手人</th>
											<th width="60">销售数量</th>
											<th width="60">销售金额</th>
											<th width="60">销售折扣</th>
											<th width="60">退货数量</th>
											<th width="60">退货金额</th>
											<th width="60">赠品数量</th>
											<th width="80">单据摘要</th>																				
											<th width="25">详情</th>
											<th width="25">隐藏</th>	
										</tr>
										<tbody id="salesOrders">
										</tbody>
										<tr class="InnerTableContent" id="pager">

											<td colspan="17"><div id="pageNav"></div></td>
										</tr>
									</table>
								</div>
							</td>
						</tr>
						 -->
					</table>
				</td>
			</tr>
		</table>
	</s:form>
	</div>
	
	<div data-options="region:'center',border:false">
			<table id="dataGrid">
			</table>
		</div>
		</div>
		
		<div id="toolbar" style="display: none;">
		
		<s:if test="#session.LOGIN_CHAIN_USER.containFunction('chainSalesJSONAction!searchSalesOrder')">																						
			<a onclick="searchOrders();" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:false">搜索单据</a>
			<a onclick="downloadSalesOrder();" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-print'">下载单据</a>
		</s:if>
	</div>		

</body>
</html>